<template>
	<div>

		<el-form ref="form" :model="form" label-width="80px">

			<el-form-item label="姓名" prop="userName">
				<el-input v-model="form.userName"></el-input>
			</el-form-item>
			<el-form-item label="性别" prop="sex">
				<el-select v-model="form.sex" :style="{width: '100%'}">
					<el-option v-for="item in sexData" :key="index" :value="item.value" :label="item.label"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="出生日期" prop="birthday">
				<el-date-picker v-model="form.birthday" format="yyyy-MM-dd HH:mm:ss" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" :style="{width: '100%'}"
				 placeholder="请输入时间" clearable>
				</el-date-picker>
				
			</el-form-item>
			<el-form-item label="健康卡号/身份证号" prop="idNumber">
				<el-input v-model="form.idNumber"></el-input>
			</el-form-item>
			<el-form-item label="地址">
				<el-input v-model="form.adresss" prop="adresss"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="save">保存</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	export default {
		name: 'HealthFileEdit',
		components: {

		},
		props: ['editfileId'],
		data() {
			return {
				form: {
					
					userName: '',
					sex: '',
					birthday: null,
					idNumber: '',
					adresss: ''
				},
				sexData: [{
					"label": "男",
					"value": "男"
				}, {
					"label": "女",
					"value": "女"
				}],
				url: '/healthFile/add'
			}
		},
		created() {
			console.log("this.editfileId:" + this.editfileId)
			if (this.editfileId) {
				this.url ='/healthFile/update'
				this.axios.get('/healthFile/toedit', resp => {
					this.form.fileId = resp.obj.fileId
					// this.form.recordNum = resp.obj.recordNum
					this.form.userName = resp.obj.userName
					this.form.sex = resp.obj.sex
					this.form.birthday = resp.obj.birthday
					this.form.idNumber = resp.obj.idNumber
					this.form.adresss = resp.obj.adresss
				}, {
					fileId: this.editfileId
				})
			}
		},
		methods: {

			save() {
				this.$refs['form'].validate((valid) => {
					if (valid) {
						this.axios.post(this.url, response => {
							// 子组件要改变父组件的值
							this.$emit('update:show', false)
							this.$emit('getData')
						}, this.form)
					}
				})
			}
		}
	}
</script>
<style>
</style>
